﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using WPFExcelReport.Helpers;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Data;
using WPFExcelReport.Helpers;
using System.Linq;
namespace WPFExcelReport
{
    public partial class TVVPACK : ViewBase
    {

        #region ==dwVVP===========
        public static readonly DependencyProperty dwVVPProperty = DependencyProperty.Register("dwVVP",
            typeof(DataRow), typeof(TVVPACK),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwVVPChanged));
        public DataRow dwVVP
        {
            get
            {
                return (DataRow)GetValue(dwVVPProperty);
            }
            set
            {
                SetValue(dwVVPProperty, value);
            }
        }
        private static void OndwVVPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TVVPACK;
            if (src != null)
            {
                src.dwVVP = (DataRow)e.NewValue;
            }
        }
        #endregion


        public TVVPACK()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VVVPACK();
            MESSAGES += "WB2KO;";
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
        }

        public override void vwMaster_CurrentChanged(object sender, System.EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwVVP = dwMaster;
        }
        public override void OnWorkflowIDChange(MessageEventArgs e)
        {
            base.OnWorkflowIDChange(e);
            MessageInfo msg = e.Info;
            string task = msg.MSGTYPE;
            switch (task)
            {
                case "WB2KO":
                    dwData = TBMain.NewRow();
                    dwData["VVPMANDANT"] = app.Mandant;
                    dwData["VVPLIEFSCH"] = msg.LIEFSCH;
                    dwData["VVPPACKNR"] = "0001";
                    SResult = ((VVVPACK)MV).QueryVVPACK(dwData, 1);
                    MergeData(SResult, true);
                     break;
            }
        }
    }
}